home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 July / CHIP 2006-07.2.iso / program / web_gelistirme / easyphp1-7_setup.exe / {app} / phpmyadmin / server_privileges.php < prev    next >
Encoding:
PHP Script  |  2003-09-07  |  92.9 KB  |  1,486 lines

  1. <?php
  2. /* $Id: server_privileges.php,v 1.37.2.1 2003/08/20 14:27:52 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Does the common work
  8.  */
  9. $js_to_run = 'server_privileges.js';
  10. require('./server_common.inc.php');
  11.  
  12.  
  13. /**
  14.  * Checks if a dropdown box has been used for selecting a database / table
  15.  */
  16. if (!empty($pred_dbname)) {
  17.     $dbname = $pred_dbname;
  18.     unset($pred_dbname);
  19. }
  20. if (!empty($pred_tablename)) {
  21.     $tablename = $pred_tablename;
  22.     unset($pred_tablename);
  23. }
  24.  
  25.  
  26. /**
  27.  * Checks if the user is allowed to do what he tries to...
  28.  */
  29. if (!$is_superuser) {
  30.     include('./server_links.inc.php');
  31.     echo '<h2>' . "\n"
  32.        . '    ' . $strPrivileges . "\n"
  33.        . '</h2>' . "\n"
  34.        . $strNoPrivileges . "\n";
  35.     include('./footer.inc.php');
  36.     exit;
  37. }
  38.  
  39.  
  40. /**
  41.  * Extracts the privilege information of a priv table row
  42.  *
  43.  * @param   array    the row
  44.  * @param   boolean  add <dfn> tag with tooltips
  45.  *
  46.  * @global  ressource  the database connection
  47.  *
  48.  * @return  array
  49.  */
  50. function PMA_extractPrivInfo($row = '', $enableHTML = FALSE)
  51. {
  52.     global $userlink;
  53.  
  54.     $grants = array(
  55.         array('Select_priv', 'SELECT', $GLOBALS['strPrivDescSelect']),
  56.         array('Insert_priv', 'INSERT', $GLOBALS['strPrivDescInsert']),
  57.         array('Update_priv', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
  58.         array('Delete_priv', 'DELETE', $GLOBALS['strPrivDescDelete']),
  59.         array('Create_priv', 'CREATE', $GLOBALS['strPrivDescCreateDb']),
  60.         array('Drop_priv', 'DROP', $GLOBALS['strPrivDescDropDb']),
  61.         array('Reload_priv', 'RELOAD', $GLOBALS['strPrivDescReload']),
  62.         array('Shutdown_priv', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']),
  63.         array('Process_priv', 'PROCESS', $GLOBALS['strPrivDescProcess' . ((!empty($row) && isset($row['Super_priv'])) || (empty($row) && isset($GLOBALS['Super_priv'])) ? '4' : '3')]),
  64.         array('File_priv', 'FILE', $GLOBALS['strPrivDescFile']),
  65.         array('References_priv', 'REFERENCES', $GLOBALS['strPrivDescReferences']),
  66.         array('Index_priv', 'INDEX', $GLOBALS['strPrivDescIndex']),
  67.         array('Alter_priv', 'ALTER', $GLOBALS['strPrivDescAlter']),
  68.         array('Show_db_priv', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']),
  69.         array('Super_priv', 'SUPER', $GLOBALS['strPrivDescSuper']),
  70.         array('Create_tmp_table_priv', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),
  71.         array('Lock_tables_priv', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']),
  72.         array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute']),
  73.         array('Repl_slave_priv', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']),
  74.         array('Repl_client_priv', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient'])
  75.     );
  76.     if (!empty($row) && isset($row['Table_priv'])) {
  77.         $sql_query = 'SHOW COLUMNS FROM `tables_priv` LIKE "Table_priv";';
  78.         $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  79.         unset($sql_query);
  80.         $row1 = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
  81.         mysql_free_result($res);
  82.         $av_grants = explode ('\',\'' , substr($row1['Type'], 5, strlen($row1['Type']) - 7));
  83.         unset($row1);
  84.         $users_grants = explode(',', $row['Table_priv']);
  85.         while (list(, $current_grant) = each($av_grants)) {
  86.             $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
  87.         }
  88.         unset($current_grant);
  89.         unset($av_grants);
  90.         unset($users_grants);
  91.     }
  92.     $privs = array();
  93.     $allPrivileges = TRUE;
  94.     while (list(, $current_grant) = each($grants)) {
  95.         if ((!empty($row) && isset($row[$current_grant[0]])) || (empty($row) && isset($GLOBALS[$current_grant[0]]))) {
  96.             if ((!empty($row) && $row[$current_grant[0]] == 'Y') || (empty($row) && ($GLOBALS[$current_grant[0]] == 'Y' || (is_array($GLOBALS[$current_grant[0]]) && count($GLOBALS[$current_grant[0]]) == $GLOBALS['column_count'] && empty($GLOBALS[$current_grant[0] . '_none']))))) {
  97.                 if ($enableHTML) {
  98.                     $privs[] = '<dfn title="' . $current_grant[2] . '">' . str_replace(' ', ' ', $current_grant[1]) . '</dfn>';
  99.                 } else {
  100.                     $privs[] = $current_grant[1];
  101.                 }
  102.             } else if (!empty($GLOBALS[$current_grant[0]]) && is_array($GLOBALS[$current_grant[0]]) && empty($GLOBALS[$current_grant[0] . '_none'])) {
  103.                 if ($enableHTML) {
  104.                     $priv_string = '<dfn title="' . $current_grant[2] . '">' . str_replace(' ', ' ', $current_grant[1]) . '</dfn>';
  105.                 } else {
  106.                     $priv_string = $current_grant[1];
  107.                 }
  108.                 $privs[] = $priv_string . ' (`' . join('`, `', $GLOBALS[$current_grant[0]]) . '`)';
  109.             } else {
  110.                 $allPrivileges = FALSE;
  111.             }
  112.         }
  113.     }
  114.     if (empty($privs)) {
  115.         if ($enableHTML) {
  116.             $privs[] = '<dfn title="' . $GLOBALS['strPrivDescUsage'] . '">USAGE</dfn>';
  117.         } else {
  118.             $privs[] = 'USAGE';
  119.         }
  120.     } else if ($allPrivileges && (!isset($GLOBALS['grant_count']) || count($privs) == $GLOBALS['grant_count'])) {
  121.         if ($enableHTML) {
  122.             $privs = array('<dfn title="' . $GLOBALS['strPrivDescAllPrivileges'] . '">ALL PRIVILEGES</dfn>');
  123.         } else {
  124.             $privs = array('ALL PRIVILEGES');
  125.         }
  126.     }
  127.     return $privs;
  128. } // end of the 'PMA_extractPrivInfo()' function
  129.  
  130. /**
  131.  * Displays the privileges form table
  132.  *
  133.  * @param   string     the database
  134.  * @param   string     the table
  135.  * @param   boolean    wheather to display the submit button or not
  136.  * @param   int        the indenting level of the code
  137.  *
  138.  * @global  array      the phpMyAdmin configuration
  139.  * @global  ressource  the database connection
  140.  *
  141.  * @return  void
  142.  */
  143. function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = 0)
  144. {
  145.     global $cfg, $userlink;
  146.  
  147.     if ($db == '*') {
  148.         $table = '*';
  149.     }
  150.     $spaces = '';
  151.     for ($i = 0; $i < $indent; $i++) {
  152.         $spaces .= '    ';
  153.     }
  154.     if (isset($GLOBALS['username'])) {
  155.         $username = $GLOBALS['username'];
  156.         $hostname = $GLOBALS['hostname'];
  157.         if ($db == '*') {
  158.             $sql_query = 'SELECT * FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '";';
  159.         } else if ($table == '*') {
  160.             $sql_query = 'SELECT * FROM `db` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '";';
  161.         } else {
  162.             $sql_query = 'SELECT `Table_priv` FROM `tables_priv` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '" AND `Table_name` = "' . $table . '";';
  163.         }
  164.         $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  165.         if ($res) {
  166.             $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
  167.         }
  168.         @mysql_free_result($res);
  169.     }
  170.     if (empty($row)) {
  171.         if ($table == '*') {
  172.             if ($db == '*') {
  173.                 $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
  174.             } else if ($table == '*') {
  175.                 $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
  176.             }
  177.             $res = PMA_mysql_query($sql_query, $userlink)
  178.                 or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  179.             while ($row1 = PMA_mysql_fetch_row($res)) {
  180.                 if (substr($row1[0], 0, 4) == 'max_') {
  181.                     $row[$row1[0]] = 0;
  182.                 } else {
  183.                     $row[$row1[0]] = 'N';
  184.                 }
  185.             }
  186.             mysql_free_result($res);
  187.         } else {
  188.             $row = array('Table_priv' => '');
  189.         }
  190.     }
  191.     if (isset($row['Table_priv'])) {
  192.         $sql_query = 'SHOW COLUMNS FROM `tables_priv` LIKE "Table_priv";';
  193.         $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  194.         unset($sql_query);
  195.         $row1 = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
  196.         mysql_free_result($res);
  197.         $av_grants = explode ('\',\'' , substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3));
  198.         unset($row1);
  199.         $users_grants = explode(',', $row['Table_priv']);
  200.         while (list(, $current_grant) = each($av_grants)) {
  201.             $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
  202.         }
  203.         unset($row['Table_priv']);
  204.         unset($current_grant);
  205.         unset($av_grants);
  206.         unset($users_grants);
  207.         if ($res = PMA_mysql_query('SHOW COLUMNS FROM `' . $db . '`.`' . $table . '`;', $userlink)) {
  208.             $columns = array();
  209.             while ($row1 = PMA_mysql_fetch_row($res)) {
  210.                 $columns[$row1[0]] = array(
  211.                     'Select' => FALSE,
  212.                     'Insert' => FALSE,
  213.                     'Update' => FALSE,
  214.                     'References' => FALSE
  215.                 );
  216.             }
  217.             mysql_free_result($res);
  218.             unset($res);
  219.             unset($row1);
  220.         }
  221.     }
  222.     if (!empty($columns)) {
  223.         $sql_query = 'SELECT `Column_name`, `Column_priv` FROM `columns_priv` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '" AND `Table_name` = "' . $table . '";';
  224.         $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  225.         while ($row1 = PMA_mysql_fetch_row($res)) {
  226.             $row1[1] = explode(',', $row1[1]);
  227.             while (list(, $current) = each($row1[1])) {
  228.                 $columns[$row1[0]][$current] = TRUE;
  229.             }
  230.         }
  231.         mysql_free_result($res);
  232.         unset($res);
  233.         unset($row1);
  234.         unset($current);
  235.         echo $spaces . '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n"
  236.            . $spaces . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n"
  237.            . $spaces . '<table border="0">' . "\n"
  238.            . $spaces . '    <tr>' . "\n"
  239.            . $spaces . '        <th colspan="6"> ' . $GLOBALS['strTblPrivileges'] . ' </th>' . "\n"
  240.            . $spaces . '    </tr>' . "\n"
  241.            . $spaces . '    <tr>' . "\n"
  242.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="6"><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></td>' . "\n"
  243.            . $spaces . '    </tr>' . "\n"
  244.            . $spaces . '    <tr>' . "\n"
  245.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '"> <tt><dfn title="' . $GLOBALS['strPrivDescSelect'] . '">SELECT</dfn></tt> </td>' . "\n"
  246.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '"> <tt><dfn title="' . $GLOBALS['strPrivDescInsert'] . '">INSERT</dfn></tt> </td>' . "\n"
  247.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '"> <tt><dfn title="' . $GLOBALS['strPrivDescUpdate'] . '">UPDATE</dfn></tt> </td>' . "\n"
  248.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '"> <tt><dfn title="' . $GLOBALS['strPrivDescReferences'] . '">REFERENCES</dfn></tt> </td>' . "\n";
  249.         list($current_grant, $current_grant_value) = each($row);
  250.         while (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
  251.             list($current_grant, $current_grant_value) = each($row);
  252.         }
  253.         echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '"/></td>' . "\n"
  254.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n"
  255.            . $spaces . '    </tr>' . "\n"
  256.            . $spaces . '    <tr>' . "\n";
  257.         $rowspan = count($row) - 5;
  258.         echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
  259.            . $spaces . '            <select name="Select_priv[]" multiple="multiple">' . "\n";
  260.         while (list($current_column, $current_column_privileges) = each($columns)) {
  261.             echo $spaces . '                <option value="' . htmlspecialchars($current_column) . '"';
  262.             if ($row['Select_priv'] == 'Y' || $current_column_privileges['Select']) {
  263.                 echo ' selected="selected"';
  264.             }
  265.             echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
  266.         }
  267.         echo $spaces . '            </select><br />' . "\n"
  268.            . $spaces . '            <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n"
  269.            . $spaces . '            <input type="checkbox" name="Select_priv_none" id="checkbox_Select_priv_none" title="' . $GLOBALS['strNone'] . '" />' . "\n"
  270.            . $spaces . '            <label for="checkbox_Select_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n"
  271.            . $spaces . '        </td>' . "\n"
  272.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
  273.            . $spaces . '            <select name="Insert_priv[]" multiple="multiple">' . "\n";
  274.         reset($columns);
  275.         while (list($current_column, $current_column_privileges) = each($columns)) {
  276.             echo $spaces . '                <option value="' . htmlspecialchars($current_column) . '"';
  277.             if ($row['Insert_priv'] == 'Y' || $current_column_privileges['Insert']) {
  278.                 echo ' selected="selected"';
  279.             }
  280.             echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
  281.         }
  282.         echo $spaces . '            </select><br />' . "\n"
  283.            . $spaces . '            <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n"
  284.            . $spaces . '            <input type="checkbox" name="Insert_priv_none" id="checkbox_Insert_priv_none" title="' . $GLOBALS['strNone'] . '" />' . "\n"
  285.            . $spaces . '            <label for="checkbox_Insert_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n"
  286.            . $spaces . '        </td>' . "\n"
  287.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
  288.            . $spaces . '            <select name="Update_priv[]" multiple="multiple">' . "\n";
  289.         reset($columns);
  290.         while (list($current_column, $current_column_privileges) = each($columns)) {
  291.             echo $spaces . '                <option value="' . htmlspecialchars($current_column) . '"';
  292.             if ($row['Update_priv'] == 'Y' || $current_column_privileges['Update']) {
  293.                 echo ' selected="selected"';
  294.             }
  295.             echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
  296.         }
  297.         echo $spaces . '            </select><br />' . "\n"
  298.            . $spaces . '            <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n"
  299.            . $spaces . '            <input type="checkbox" name="Update_priv_none" id="checkbox_Update_priv_none" title="' . $GLOBALS['strNone'] . '" />' . "\n"
  300.            . $spaces . '            <label for="checkbox_Update_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n"
  301.            . $spaces . '        </td>' . "\n"
  302.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
  303.            . $spaces . '            <select name="References_priv[]" multiple="multiple">' . "\n";
  304.         reset($columns);
  305.         while (list($current_column, $current_column_privileges) = each($columns)) {
  306.             echo $spaces . '                <option value="' . htmlspecialchars($current_column) . '"';
  307.             if ($row['References_priv'] == 'Y' || $current_column_privileges['References']) {
  308.                 echo ' selected="selected"';
  309.             }
  310.             echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
  311.         }
  312.         echo $spaces . '            </select><br />' . "\n"
  313.            . $spaces . '            <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n"
  314.            . $spaces . '            <input type="checkbox" name="References_priv_none" id="checkbox_References_priv_none" title="' . $GLOBALS['strNone'] . '" />' . "\n"
  315.            . $spaces . '            <label for="checkbox_References_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n"
  316.            . $spaces . '        </td>' . "\n";
  317.         unset($rowspan);
  318.         list($current_grant, $current_grant_value) = each($row);
  319.         while (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
  320.             list($current_grant, $current_grant_value) = each($row);
  321.         }
  322.         echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '"/></td>' . "\n"
  323.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n"
  324.            . $spaces . '    </tr>' . "\n";
  325.         while (list($current_grant, $current_grant_value) = each($row)) {
  326.             if (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
  327.                 continue;
  328.             }
  329.             echo $spaces . '    <tr>' . "\n"
  330.                . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '"/></td>' . "\n"
  331.                . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n"
  332.                . $spaces . '    </tr>' . "\n";
  333.         }
  334.     } else {
  335.         $privTable[0] = array(
  336.             array('Select', 'SELECT', $GLOBALS['strPrivDescSelect']),
  337.             array('Insert', 'INSERT', $GLOBALS['strPrivDescInsert']),
  338.             array('Update', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
  339.             array('Delete', 'DELETE', $GLOBALS['strPrivDescDelete'])
  340.         );
  341.         if ($db == '*') {
  342.             $privTable[0][] = array('File', 'FILE', $GLOBALS['strPrivDescFile']);
  343.         }
  344.         $privTable[1] = array(
  345.             array('Create', 'CREATE', ($table == '*' ? $GLOBALS['strPrivDescCreateDb'] : $GLOBALS['strPrivDescCreateTbl'])),
  346.             array('Alter', 'ALTER', $GLOBALS['strPrivDescAlter']),
  347.             array('Index', 'INDEX', $GLOBALS['strPrivDescIndex']),
  348.             array('Drop', 'DROP', ($table == '*' ? $GLOBALS['strPrivDescDropDb'] : $GLOBALS['strPrivDescDropTbl']))
  349.         );
  350.         if (isset($row['Create_tmp_table_priv'])) {
  351.             $privTable[1][] = array('Create_tmp_table', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']);
  352.         }
  353.         $privTable[2] = array();
  354.         if (isset($row['Grant_priv'])) {
  355.             $privTable[2][] = array('Grant', 'GRANT', $GLOBALS['strPrivDescGrant']);
  356.         }
  357.         if ($db == '*') {
  358.             if (isset($row['Super_priv'])) {
  359.                 $privTable[2][] = array('Super', 'SUPER', $GLOBALS['strPrivDescSuper']);
  360.                 $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess4']);
  361.             } else {
  362.                 $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess3']);
  363.             }
  364.             $privTable[2][] = array('Reload', 'RELOAD', $GLOBALS['strPrivDescReload']);
  365.             $privTable[2][] = array('Shutdown', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']);
  366.             if (isset($row['Show_db_priv'])) {
  367.                 $privTable[2][] = array('Show_db', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']);
  368.             }
  369.             if (isset($row['Lock_tables_priv'])) {
  370.                 $privTable[2][] = array('Lock_tables', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']);
  371.             }
  372.         }
  373.         $privTable[2][] = array('References', 'REFERENCES', $GLOBALS['strPrivDescReferences']);
  374.         if ($db == '*') {
  375.             if (isset($row['Execute_priv'])) {
  376.                 $privTable[2][] = array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute']);
  377.             }
  378.             if (isset($row['Repl_client_priv'])) {
  379.                 $privTable[2][] = array('Repl_client', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']);
  380.             }
  381.             if (isset($row['Repl_slave_priv'])) {
  382.                 $privTable[2][] = array('Repl_slave', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']);
  383.             }
  384.         }
  385.         echo $spaces . '<input type="hidden" name="grant_count" value="' . (count($privTable[0]) + count($privTable[1]) + count($privTable[2]) - (isset($row['Grant_priv']) ? 1 : 0)) . '" />' . "\n"
  386.            . $spaces . '<table border="0">' . "\n"
  387.            . $spaces . '    <tr>' . "\n"
  388.            . $spaces . '        <th colspan="6"> ' . ($db == '*' ? $GLOBALS['strGlobalPrivileges'] : ($table == '*' ? $GLOBALS['strDbPrivileges'] : $GLOBALS['strTblPrivileges'])) . ' </th>' . "\n"
  389.            . $spaces . '    </tr>' . "\n"
  390.            . $spaces . '    <tr>' . "\n"
  391.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="6"><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></td>' . "\n"
  392.            . $spaces . '    </tr>' . "\n"
  393.            . $spaces . '    <tr>' . "\n"
  394.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2"> <b><i>' . $GLOBALS['strData'] . '</i></b> </td>' . "\n"
  395.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2"> <b><i>' . $GLOBALS['strStructure'] . '</i></b> </td>' . "\n"
  396.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2"> <b><i>' . $GLOBALS['strAdministration'] . '</i></b> </td>' . "\n"
  397.            . $spaces . '    </tr>' . "\n";
  398.         $limitTable = FALSE;
  399.         for ($i = 0; isset($privTable[0][$i]) || isset($privTable[1][$i]) || isset($privTable[2][$i]); $i++) {
  400.             echo $spaces . '    <tr>' . "\n";
  401.             for ($j = 0; $j < 3; $j++) {
  402.                 if (isset($privTable[$j][$i])) {
  403.                     echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $privTable[$j][$i][0] . '_priv" id="checkbox_' . $privTable[$j][$i][0] . '_priv" value="Y" ' . ($row[$privTable[$j][$i][0] . '_priv'] == 'Y' ? 'checked="checked" ' : '') . 'title="' . $privTable[$j][$i][2] . '"/></td>' . "\n"
  404.                        . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $privTable[$j][$i][0] . '_priv"><tt><dfn title="' . $privTable[$j][$i][2] . '">' . $privTable[$j][$i][1] . '</dfn></tt></label></td>' . "\n";
  405.                 } else if ($db == '*' && !isset($privTable[0][$i]) && !isset($privTable[1][$i])
  406.                     && isset($row['max_questions']) && isset($row['max_updates']) && isset($row['max_connections'])
  407.                     && !$limitTable) {
  408.                     echo $spaces . '        <td colspan="4" rowspan="' . (count($privTable[2]) - $i) . '">' . "\n"
  409.                        . $spaces . '            <table border="0">' . "\n"
  410.                        . $spaces . '                <tr>' . "\n"
  411.                        . $spaces . '                    <th colspan="2"> ' . $GLOBALS['strResourceLimits'] . ' </th>' . "\n"
  412.                        . $spaces . '                </tr>' . "\n"
  413.                        . $spaces . '                <tr>' . "\n"
  414.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="2"><small><i>' . $GLOBALS['strZeroRemovesTheLimit'] . '</i></small></td>' . "\n"
  415.                        . $spaces . '                </tr>' . "\n"
  416.                        . $spaces . '                <tr>' . "\n"
  417.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="text_max_questions"><tt><dfn title="' . $GLOBALS['strPrivDescMaxQuestions'] . '">MAX QUERIES PER HOUR</dfn></tt></label></td>' . "\n"
  418.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="text" class="textfield" name="max_questions" id="text_max_questions" value="' . $row['max_questions'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxQuestions'] . '" /></td>' . "\n"
  419.                        . $spaces . '                </tr>' . "\n"
  420.                        . $spaces . '                <tr>' . "\n"
  421.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="text_max_updates"><tt><dfn title="' . $GLOBALS['strPrivDescMaxUpdates'] . '">MAX UPDATES PER HOUR</dfn></tt></label></td>' . "\n"
  422.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="text" class="textfield" name="max_updates" id="text_max_updates" value="' . $row['max_updates'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUpdates'] . '" /></td>' . "\n"
  423.                        . $spaces . '                </tr>' . "\n"
  424.                        . $spaces . '                <tr>' . "\n"
  425.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="text_max_connections"><tt><dfn title="' . $GLOBALS['strPrivDescMaxConnections'] . '">MAX CONNECTIONS PER HOUR</dfn></tt></label></td>' . "\n"
  426.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="text" class="textfield" name="max_connections" id="text_max_connections" value="' . $row['max_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxConnections'] . '" /></td>' . "\n"
  427.                        . $spaces . '                </tr>' . "\n"
  428.                        . $spaces . '            </table>' . "\n"
  429.                        . $spaces . '        </td>' . "\n";
  430.                     $limitTable = TRUE;
  431.                 } else if (!$limitTable) {
  432.                     echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="2"> </td>' . "\n";
  433.                 }
  434.             }
  435.         }
  436.         echo $spaces . '    </tr>' . "\n";
  437.     }
  438.     if ($submit) {
  439.         echo $spaces . '    <tr>' . "\n"
  440.            . $spaces . '        <td colspan="6" align="center">' . "\n"
  441.            . $spaces . '            <input type="submit" name="update_privs" value="' . $GLOBALS['strGo'] . '" />' . "\n"
  442.            . $spaces . '        </td>' . "\n"
  443.            . $spaces . '    </tr>' . "\n";
  444.     }
  445.     echo $spaces . '</table>' . "\n";
  446. } // end of the 'PMA_displayPrivTable()' function
  447.  
  448.  
  449. /**
  450.  * Displays the fields used by the "new user" form as well as the
  451.  * "change login information / copy user" form.
  452.  *
  453.  * @param   string     are we creating a new user or are we just changing one?
  454.  *                     (allowed values: 'new', 'change')
  455.  * @param   int        the indenting level of the code
  456.  *
  457.  * @global  array      the phpMyAdmin configuration
  458.  * @global  ressource  the database connection
  459.  *
  460.  * @return  void
  461.  */
  462. function PMA_displayLoginInformationFields($mode = 'new', $indent = 0)
  463. {
  464.     global $cfg, $userlink;
  465.     $spaces = '';
  466.     for ($i = 0; $i < $indent; $i++) {
  467.         $spaces .= '    ';
  468.     }
  469.     echo $spaces . '<tr>' . "\n"
  470.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  471.        . $spaces . '        <label for="select_pred_username">' . "\n"
  472.        . $spaces . '            ' . $GLOBALS['strUserName'] . ':' . "\n"
  473.        . $spaces . '        </label>' . "\n"
  474.        . $spaces . '    </td>' . "\n"
  475.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  476.        . $spaces . '        <select name="pred_username" id="select_pred_username" title="' . $GLOBALS['strUserName'] . '"' . "\n"
  477.        . $spaces . '            onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">' . "\n"
  478.        . $spaces . '            <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyUser'] . '</option>' . "\n"
  479.        . $spaces . '            <option value="userdefined"' . ((!isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined') ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
  480.        . $spaces . '        </select>' . "\n"
  481.        . $spaces . '    </td>' . "\n"
  482.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  483.        . $spaces . '        <input type="text" class="textfield" name="username" class="textfield" title="' . $GLOBALS['strUserName'] . '"' . (empty($GLOBALS['username']) ? '' : ' value="' . (isset($GLOBALS['new_username']) ? $GLOBALS['new_username'] : $GLOBALS['username']) . '"') . ' onchange="pred_username.value = \'userdefined\';" />' . "\n"
  484.        . $spaces . '    </td>' . "\n"
  485.        . $spaces . '</tr>' . "\n"
  486.        . $spaces . '<tr>' . "\n"
  487.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  488.        . $spaces . '        <label for="select_pred_hostname">' . "\n"
  489.        . $spaces . '            ' . $GLOBALS['strHost'] . ':' . "\n"
  490.        . $spaces . '        </label>' . "\n"
  491.        . $spaces . '    </td>' . "\n"
  492.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  493.        . $spaces . '        <select name="pred_hostname" id="select_pred_hostname" title="' . $GLOBALS['strHost'] . '"' . "\n";
  494.     $res = PMA_mysql_query('SELECT USER();', $userlink);
  495.     $row = @PMA_mysql_fetch_row($res);
  496.     @mysql_free_result($res);
  497.     unset($res);
  498.     if (!empty($row[0])) {
  499.         $thishost = str_replace("'", '', substr($row[0], (strrpos($row[0], '@') + 1)));
  500.         if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
  501.             unset($thishost);
  502.         }
  503.     }
  504.     echo $spaces . '            onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
  505.        . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
  506.        . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
  507.     unset($row);
  508.     echo $spaces . '            <option value="any"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any') ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyHost'] . '</option>' . "\n"
  509.        . $spaces . '            <option value="localhost"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost') ? ' selected="selected"' : '') . '>' . $GLOBALS['strLocalhost'] . '</option>' . "\n";
  510.     if (!empty($thishost)) {
  511.         echo $spaces . '            <option value="thishost"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost') ? ' selected="selected"' : '') . '>' . $GLOBALS['strThisHost'] . '</option>' . "\n";
  512.     }
  513.     unset($thishost);
  514.     echo $spaces . '            <option value="hosttable"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable') ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseHostTable'] . '</option>' . "\n"
  515.        . $spaces . '            <option value="userdefined"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined') ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
  516.        . $spaces . '        </select>' . "\n"
  517.        . $spaces . '    </td>' . "\n"
  518.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  519.        . $spaces . '        <input type="text" class="textfield" name="hostname" value="' . ( isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '' ) . '" class="textfield" title="' . $GLOBALS['strHost'] . '" onchange="pred_hostname.value = \'userdefined\';" />' . "\n"
  520.        . $spaces . '    </td>' . "\n"
  521.        . $spaces . '</tr>' . "\n"
  522.        . $spaces . '<tr>' . "\n"
  523.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  524.        . $spaces . '        <label for="select_pred_password">' . "\n"
  525.        . $spaces . '            ' . $GLOBALS['strPassword'] . ':' . "\n"
  526.        . $spaces . '        </label>' . "\n"
  527.        . $spaces . '    </td>' . "\n"
  528.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  529.        . $spaces . '        <select name="pred_password" id="select_pred_password" title="' . $GLOBALS['strPassword'] . '"' . "\n"
  530.        . $spaces . '            onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">' . "\n"
  531.        . ($mode == 'change' ? $spaces . '            <option value="keep" selected="selected">' . $GLOBALS['strKeepPass'] . '</option>' . "\n" : '')
  532.        . $spaces . '            <option value="none">' . $GLOBALS['strNoPassword'] . '</option>' . "\n"
  533.        . $spaces . '            <option value="userdefined"' . ($mode == 'change' ? '' : ' selected="selected"') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
  534.        . $spaces . '        </select>' . "\n"
  535.        . $spaces . '    </td>' . "\n"
  536.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  537.        . $spaces . '        <input type="password" name="pma_pw" class="textfield" title="' . $GLOBALS['strPassword'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
  538.        . $spaces . '    </td>' . "\n"
  539.        . $spaces . '</tr>' . "\n"
  540.        . $spaces . '<tr>' . "\n"
  541.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  542.        . $spaces . '        <label for="text_pma_pw2">' . "\n"
  543.        . $spaces . '            ' . $GLOBALS['strReType'] . ':' . "\n"
  544.        . $spaces . '        </label>' . "\n"
  545.        . $spaces . '    </td>' . "\n"
  546.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '"> </td>' . "\n"
  547.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  548.        . $spaces . '        <input type="password" name="pma_pw2" id="text_pma_pw2" class="textfield" title="' . $GLOBALS['strReType'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
  549.        . $spaces . '    </td>' . "\n"
  550.        . $spaces . '</tr>' . "\n";
  551. } // end of the 'PMA_displayUserAndHostFields()' function
  552.  
  553.  
  554. /**
  555.  * Changes / copies a user, part I
  556.  */
  557. if (!empty($change_copy)) {
  558.     $local_query = 'SELECT * FROM `mysql`.`user` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '";';
  559.     $res = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query);
  560.     if (!$res) {
  561.         $message = $strNoUsersFound;
  562.         unset($change_copy);
  563.     } else {
  564.         $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
  565.         extract($row, EXTR_OVERWRITE);
  566.         mysql_free_result($res);
  567.         $queries = array();
  568.     }
  569. }
  570.  
  571.  
  572. /**
  573.  * Adds a user
  574.  *   (Changes / copies a user, part II)
  575.  */
  576. if (!empty($adduser_submit) || !empty($change_copy)) {
  577.     unset($sql_query);
  578.     if ($pred_username == 'any') {
  579.         $username = '';
  580.     }
  581.     switch ($pred_hostname) {
  582.         case 'any':
  583.             $hostname = '%';
  584.             break;
  585.         case 'localhost':
  586.             $hostname = 'localhost';
  587.             break;
  588.         case 'hosttable':
  589.             $hostname = '';
  590.             break;
  591.         case 'thishost':
  592.             $res = PMA_mysql_query('SELECT USER();', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SELECT USER();');
  593.             $row = PMA_mysql_fetch_row($res);
  594.             mysql_free_result($res);
  595.             unset($res);
  596.             $hostname = substr($row[0], (strrpos($row[0], '@') + 1));
  597.             unset($row);
  598.             break;
  599.     }
  600.     $local_query = 'SELECT "foo" FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '";';
  601.     $res = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query);
  602.     unset($local_query);
  603.     if (mysql_affected_rows($userlink) == 1) {
  604.         $message = sprintf($strUserAlreadyExists, '<i>\'' . $username . '\'@\'' . $hostname . '\'</i>');
  605.         $adduser = 1;
  606.     } else {
  607.         if (PMA_MYSQL_INT_VERSION >= 32211) {
  608.             $real_sql_query = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON *.* TO "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '"';
  609.             if ($pred_password != 'none' && $pred_password != 'keep') {
  610.                 $pma_pw_hidden = '';
  611.                 for ($i = 0; $i < strlen($pma_pw); $i++) {
  612.                     $pma_pw_hidden .= '*';
  613.                 }
  614.                 $sql_query = $real_sql_query . ' IDENTIFIED BY "' . $pma_pw_hidden . '"';
  615.                 $real_sql_query .= ' IDENTIFIED BY "' . $pma_pw . '"';
  616.             } else {
  617.                 if ($pred_password == 'keep' && !empty($Password)) {
  618.                     $real_sql_query .= ' IDENTIFIED BY PASSWORD "' . $Password . '"';
  619.                 }
  620.                 $sql_query = $real_sql_query;
  621.             }
  622.             if ((isset($Grant_priv) && $Grant_priv == 'Y') || (PMA_MYSQL_INT_VERSION >= 40002 && (isset($max_questions) || isset($max_connections) || isset($max_updates)))) {
  623.                 $real_sql_query .= 'WITH';
  624.                 $sql_query .= 'WITH';
  625.                 if (isset($Grant_priv) && $Grant_priv == 'Y') {
  626.                     $real_sql_query .= ' GRANT OPTION';
  627.                     $sql_query .= ' GRANT OPTION';
  628.                 }
  629.                 if (PMA_MYSQL_INT_VERSION >= 40002) {
  630.                     if (isset($max_questions)) {
  631.                         $real_sql_query .= ' MAX_QUERIES_PER_HOUR ' . (int)$max_questions;
  632.                         $sql_query .= ' MAX_QUERIES_PER_HOUR ' . (int)$max_questions;
  633.                     }
  634.                     if (isset($max_connections)) {
  635.                         $real_sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . (int)$max_connections;
  636.                         $sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . (int)$max_connections;
  637.                     }
  638.                     if (isset($max_updates)) {
  639.                         $real_sql_query .= ' MAX_UPDATES_PER_HOUR ' . (int)$max_updates;
  640.                         $sql_query .= ' MAX_UPDATES_PER_HOUR ' . (int)$max_updates;
  641.                     }
  642.                 }
  643.             }
  644.             $real_sql_query .= ';';
  645.             $sql_query .= ';';
  646.             if (empty($change_copy)) {
  647.                 PMA_mysql_query($real_sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  648.                 $message = $strAddUserMessage;
  649.             } else {
  650.                 $queries[] = $sql_query;
  651.             }
  652.             unset($real_sql_query);
  653.         } else {
  654.             $privileges = PMA_extractPrivInfo();
  655.             $real_sql_query = 'INSERT INTO `user` SET `Host` = "' . $hostname . '", `User` = "' . PMA_sqlAddslashes($username) . '"';
  656.             if ($pred_password != 'none') {
  657.                 $pma_pw_hidden = '';
  658.                 for ($i = 0; $i < strlen($pma_pw); $i++) {
  659.                     $pma_pw_hidden .= '*';
  660.                 }
  661.                 $sql_query = $real_sql_query . ', `Password` = PASSWORD("' . $pma_pw_hidden . '")';
  662.                 $real_sql_query .= ', `Password` = PASSWORD("' . $pma_pw . '")';
  663.             } else {
  664.                 $sql_query = $real_sql_query;
  665.             }
  666.             while (list(, $priv) = each($privileges)) {
  667.                 $real_sql_query .= ', `' . substr($priv, 0, 1) . strtolower(substr($priv, 1)) . '_priv` = "Y"';
  668.                 $sql_query .= ', `' . substr($priv, 0, 1) . strtolower(substr($priv, 1)) . '_priv` = "Y"';
  669.             }
  670.             PMA_mysql_query($real_sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink));
  671.             unset($real_sql_query);
  672.             $message = $strAddUserMessage . '<br />' . "\n" . $strRememberReload;
  673.         }
  674.         mysql_free_result($res);
  675.         unset($res);
  676.     }
  677. }
  678.  
  679.  
  680. /**
  681.  * Changes / copies a user, part III
  682.  */
  683. if (!empty($change_copy)) {
  684.     $local_query = 'SELECT * FROM `mysql`.`db` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '";';
  685.     $res = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query);
  686.     while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
  687.         $queries[] = 'GRANT ' . join(', ', PMA_extractPrivInfo($row)) . ' ON `' . $row['Db'] . '`.* TO "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '"' . ($row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION' : '') . ';';
  688.     }
  689.     mysql_free_result($res);
  690.     $local_query = 'SELECT `Db`, `Table_name`, `Table_priv` FROM `mysql`.`tables_priv` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '";';
  691.     $res = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query);
  692.     while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
  693.         $local_query = 'SELECT `Column_name`, `Column_priv` FROM `mysql`.`columns_priv` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '" AND `Db` = "' . $row['Db'] . '";';
  694.         $res2 = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query);
  695.         $tmp_privs1 = PMA_extractPrivInfo($row);
  696.         $tmp_privs2 = array(
  697.             'Select' => array(),
  698.             'Insert' => array(),
  699.             'Update' => array(),
  700.             'References' => array()
  701.         );
  702.         while ($row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC)) {
  703.             $tmp_array = explode(',', $row2['Column_priv']);
  704.             if (in_array('Select', $tmp_array)) {
  705.                 $tmp_privs2['Select'][] = $row2['Column_name'];
  706.             }
  707.             if (in_array('Insert', $tmp_array)) {
  708.                 $tmp_privs2['Insert'][] = $row2['Column_name'];
  709.             }
  710.             if (in_array('Update', $tmp_array)) {
  711.                 $tmp_privs2['Update'][] = $row2['Column_name'];
  712.             }
  713.             if (in_array('References', $tmp_array)) {
  714.                 $tmp_privs2['References'][] = $row2['Column_name'];
  715.             }
  716.             unset($tmp_array);
  717.         }
  718.         if (count($tmp_privs2['Select']) > 0 && !in_array('SELECT', $tmp_privs1)) {
  719.             $tmp_privs1[] = 'SELECT (`' . join('`, `', $tmp_privs2['Select']) . '`)';
  720.         }
  721.         if (count($tmp_privs2['Insert']) > 0 && !in_array('INSERT', $tmp_privs1)) {
  722.             $tmp_privs1[] = 'INSERT (`' . join(', ', $tmp_privs2['Insert']) . '`)';
  723.         }
  724.         if (count($tmp_privs2['Update']) > 0 && !in_array('UPDATE', $tmp_privs1)) {
  725.             $tmp_privs1[] = 'UPDATE (`' . join(', ', $tmp_privs2['Update']) . '`)';
  726.         }
  727.         if (count($tmp_privs2['References']) > 0 && !in_array('REFERENCES', $tmp_privs1)) {
  728.             $tmp_privs1[] = 'REFERENCES (`' . join(', ', $tmp_privs2['References']) . '`)';
  729.         }
  730.         unset($tmp_privs2);
  731.         $queries[] = 'GRANT ' . join(', ', $tmp_privs1) . ' ON `' . $row['Db'] . '`.`' . $row['Table_name'] . '` TO "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '"' . (in_array('Grant', explode(',', $row['Table_priv'])) ? ' WITH GRANT OPTION' : '') . ';';
  732.     }
  733. }
  734.  
  735.  
  736. /**
  737.  * Updates privileges
  738.  */
  739. if (!empty($update_privs)) {
  740.     if (PMA_MYSQL_INT_VERSION >= 32211) {
  741.         $db_and_table = empty($dbname) ? '*.*' : PMA_backquote($dbname) . '.' . (empty($tablename) ? '*' : PMA_backquote($tablename));
  742.         $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table . ' FROM "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '";';
  743.         if (!isset($Grant_priv) || $Grant_priv != 'Y') {
  744.             $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table . ' FROM "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '";';
  745.         }
  746.         $sql_query2 = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON ' . $db_and_table . ' TO "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '"';
  747.         if ((isset($Grant_priv) && $Grant_priv == 'Y') || (empty($dbname) && PMA_MYSQL_INT_VERSION >= 40002 && (isset($max_questions) || isset($max_connections) || isset($max_updates)))) {
  748.             $sql_query2 .= 'WITH';
  749.             if (isset($Grant_priv) && $Grant_priv == 'Y') {
  750.                 $sql_query2 .= ' GRANT OPTION';
  751.             }
  752.             if (PMA_MYSQL_INT_VERSION >= 40002) {
  753.                 if (isset($max_questions)) {
  754.                     $sql_query2 .= ' MAX_QUERIES_PER_HOUR ' . (int)$max_questions;
  755.                 }
  756.                 if (isset($max_connections)) {
  757.                     $sql_query2 .= ' MAX_CONNECTIONS_PER_HOUR ' . (int)$max_connections;
  758.                 }
  759.                 if (isset($max_updates)) {
  760.                     $sql_query2 .= ' MAX_UPDATES_PER_HOUR ' . (int)$max_updates;
  761.                 }
  762.             }
  763.         }
  764.         $sql_query2 .= ';';
  765.         PMA_mysql_query($sql_query0, $userlink); // this query may fail, but this does not matter :o)
  766.         if (isset($sql_query1)) {
  767.             PMA_mysql_query($sql_query1, $userlink); // this one may fail, too...
  768.         }
  769.         PMA_mysql_query($sql_query2, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query2);
  770.         $sql_query = $sql_query0 . ' ' . (isset($sql_query1) ? $sql_query1 . ' ' : '') . $sql_query2;
  771.         $message = sprintf($strUpdatePrivMessage, '\'' . $username . '\'@\'' . $hostname . '\'');
  772.     } else {
  773.         $sql_query = 'SHOW COLUMNS FROM `user`;';
  774.         $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink));
  775.         $grants = array();
  776.         while ($row = PMA_mysql_fetch_row($res)) {
  777.             if (substr($row[0], -5) == '_priv') {
  778.                 $grants[] = PMA_backquote($row[0]) . ' = "' . (empty($$row[0]) ? 'N' : 'Y') . '"';
  779.             }
  780.         }
  781.         mysql_free_result($res);
  782.         unset($res);
  783.         unset($row);
  784.         $sql_query = 'UPDATE `user` SET ' . join(', ', $grants) . ' WHERE `User` = "' . $username . '" AND `Host` = "' . $hostname . '";';
  785.         PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink));
  786.         $message = sprintf($strUpdatePrivMessage, '\'' . $username . '\'@\'' . $hostname . '\'') . '<br />' . "\n" . $strRememberReload;
  787.     }
  788. }
  789.  
  790.  
  791. /**
  792.  * Revokes Privileges
  793.  */
  794. if (!empty($revokeall)) {
  795.     if (PMA_MYSQL_INT_VERSION >= 32211) {
  796.         $db_and_table = PMA_backquote($dbname) . '.' . (empty($tablename) ? '*' : PMA_backquote($tablename));
  797.         $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table . ' FROM "' . $username . '"@"' . $hostname . '";';
  798.         $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table . ' FROM "' . $username . '"@"' . $hostname . '";';
  799.         PMA_mysql_query($sql_query0, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query0);
  800.         PMA_mysql_query($sql_query1, $userlink); // this one may fail, too...
  801.         $sql_query = $sql_query0 . ' ' . $sql_query1;
  802.         $message = sprintf($strRevokeMessage, '\'' . $username . '\'@\'' . $hostname . '\'');
  803.     }
  804.     if (empty($tablename)) {
  805.         unset($dbname);
  806.     } else {
  807.         unset($tablename);
  808.     }
  809. }
  810.  
  811.  
  812. /**
  813.  * Updates the password
  814.  */
  815. if (!empty($change_pw)) {
  816.     if ($nopass == 1) {
  817.         $sql_query = 'SET PASSWORD FOR "' . $username . '"@"' . $hostname . '" = ""';
  818.         PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink));
  819.         $message = sprintf($strPasswordChanged, '\'' . $username . '\'@\'' . $hostname . '\'');
  820.     } else if (empty($pma_pw) || empty($pma_pw2)) {
  821.         $message = $strPasswordEmpty;
  822.     } else if ($pma_pw != $pma_pw2) {
  823.         $message = $strPasswordNotSame;
  824.     } else {
  825.         $hidden_pw = '';
  826.         for ($i = 0; $i < strlen($pma_pw); $i++) {
  827.             $hidden_pw .= '*';
  828.         }
  829.         $local_query = 'SET PASSWORD FOR "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '" = PASSWORD("' . PMA_sqlAddslashes($pma_pw) . '")';
  830.         $sql_query = 'SET PASSWORD FOR "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '" = PASSWORD("' . $hidden_pw . '")';
  831.         PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink));
  832.         $message = sprintf($strPasswordChanged, '\'' . $username . '\'@\'' . $hostname . '\'');
  833.     }
  834. }
  835.  
  836.  
  837. /**
  838.  * Deletes users
  839.  *   (Changes / copies a user, part IV)
  840.  */
  841. if (!empty($delete) || (!empty($change_copy) && $mode < 4)) {
  842.     if (!empty($change_copy)) {
  843.         $selected_usr = array($old_username . '@' . $old_hostname);
  844.     } else {
  845.         $queries = array();
  846.     }
  847.     for ($i = 0; isset($selected_usr[$i]); $i++) {
  848.         list($this_user, $this_host) = explode('@', $selected_usr[$i]);
  849.         $queries[] = '# ' . sprintf($strDeleting, '\'' . $this_user . '\'@\'' . $this_host . '\'') . ' ...';
  850.         if ($mode == 2) {
  851.             // The SHOW GRANTS query may fail if the user has not been loaded
  852.             // into memory
  853.             $res = PMA_mysql_query('SHOW GRANTS FOR "' . PMA_sqlAddslashes($this_user) . '"@"' . $this_host . '";', $userlink);
  854.             if ($res) {
  855.                 $queries[] = 'REVOKE ALL PRIVILEGES ON *.* FROM "' . PMA_sqlAddslashes($this_user) . '"@"' . $this_host . '";';
  856.                 while ($row = PMA_mysql_fetch_row($res)) {
  857.                     $this_table = substr($row[0], (strpos($row[0], 'ON') + 3), (strpos($row[0], ' TO ') - strpos($row[0], 'ON') - 3));
  858.                     if ($this_table != '*.*') {
  859.                         $queries[] = 'REVOKE ALL PRIVILEGES ON ' . $this_table . ' FROM "' . PMA_sqlAddslashes($this_user) . '"@"' . $this_host . '";';
  860.                         $queries[] = 'REVOKE GRANT OPTION ON ' . $this_table . ' FROM "' . PMA_sqlAddslashes($this_user) . '"@"' . $this_host . '";';
  861.                     }
  862.                     unset($this_table);
  863.                 }
  864.                 mysql_free_result($res);
  865.             }
  866.             unset($res);
  867.         }
  868.         $queries[] = 'DELETE FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($this_user) . '" AND `Host` = "' . $this_host . '";';
  869.         if ($mode != 2) {
  870.             // If we REVOKE the table grants, we should not need to modify the
  871.             // `db`, `tables_priv` and `columns_priv` tables manually...
  872.             $queries[] = 'DELETE FROM `db` WHERE `User` = "' . PMA_sqlAddslashes($this_user) . '" AND `Host` = "' . $this_host . '";';
  873.             $queries[] = 'DELETE FROM `tables_priv` WHERE `User` = "' . PMA_sqlAddslashes($this_user) . '" AND `Host` = "' . $this_host . '";';
  874.             $queries[] = 'DELETE FROM `columns_priv` WHERE `User` = "' . PMA_sqlAddslashes($this_user) . '" AND `Host` = "' . $this_host . '";';
  875.         }
  876.         if (!empty($drop_users_db)) {
  877.             $queries[] = 'DROP DATABASE IF EXISTS ' . PMA_backquote($this_user) . ';';
  878.         }
  879.     }
  880.     if (empty($change_copy)) {
  881.         if (empty($queries)) {
  882.             $message = $strError . ': ' . $strDeleteNoUsersSelected;
  883.         } else {
  884.             if ($mode == 3) {
  885.                 $queries[] = '# ' . $strReloadingThePrivileges . ' ...';
  886.                 $queries[] = 'FLUSH PRIVILEGES;';
  887.             }
  888.             while (list(, $sql_query) = each($queries)) {
  889.                 if (substr($sql_query, 0, 1) != '#') {
  890.                     PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink));
  891.                 }
  892.             }
  893.             $sql_query = join("\n", $queries);
  894.             $message = $strUsersDeleted;
  895.         }
  896.         unset($queries);
  897.     }
  898. }
  899.  
  900.  
  901. /**
  902.  * Changes / copies a user, part V
  903.  */
  904. if (!empty($change_copy)) {
  905.     while (list(, $sql_query) = each($queries)) {
  906.         if (substr($sql_query, 0, 1) != '#') {
  907.             PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink));
  908.         }
  909.     }
  910.     $message = $strSuccess;
  911.     $sql_query = join("\n", $queries);
  912. }
  913.  
  914.  
  915. /**
  916.  * Reloads the privilege tables into memory
  917.  */
  918. if (!empty($flush_privileges)) {
  919.     $sql_query = 'FLUSH PRIVILEGES';
  920.     if (@PMA_mysql_query($sql_query, $userlink)) {
  921.         $message = $strPrivilegesReloaded;
  922.     } else {
  923.         PMA_mysqlDie(PMA_mysql_error($userlink));
  924.     }
  925. }
  926.  
  927.  
  928. /**
  929.  * Displays the links
  930.  */
  931. require('./server_links.inc.php');
  932.  
  933.  
  934. /**
  935.  * Displays the page
  936.  */
  937. if (empty($adduser) && empty($checkprivs)) {
  938.     if (!isset($username)) {
  939.         // No username is given --> display the overview
  940.         echo '<h2>' . "\n"
  941.            . '    ' . $strUserOverview . "\n"
  942.            . '</h2>' . "\n";
  943.         $oldPrivTables = FALSE;
  944.         if (PMA_MYSQL_INT_VERSION >= 40002) {
  945.             $res = PMA_mysql_query('SELECT `User`, `Host`, IF(`Password` = "", "N", "Y") AS "Password", `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv` FROM `user` ORDER BY `User` ASC, `Host` ASC;', $userlink);
  946.             if (!$res) {
  947.                 // the query failed! This may have two reasons:
  948.                 // - the user has not enough privileges
  949.                 // - the privilege tables use a structure of an earlier version.
  950.                 $oldPrivTables = TRUE;
  951.             }
  952.         }
  953.         if (empty($res) || (PMA_MYSQL_INT_VERSION >= 32211 && PMA_MYSQL_INT_VERSION < 40002)) {
  954.             $res = PMA_mysql_query('SELECT `User`, `Host`, IF(`Password` = "", "N", "Y") AS "Password", `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Index_priv`, `Alter_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv` FROM `user`  ORDER BY `User` ASC, `Host` ASC;', $userlink);
  955.             if (!$res) {
  956.                 // the query failed! This may have two reasons:
  957.                 // - the user has not enough privileges
  958.                 // - the privilege tables use a structure of an earlier version.
  959.                 $oldPrivTables = TRUE;
  960.             }
  961.         }
  962.         if (empty($res) || PMA_MYSQL_INT_VERSION < 32211) {
  963.             $res = PMA_mysql_query('SELECT * FROM `user` ORDER BY `User` ASC, `Host` ASC;', $userlink);
  964.         }
  965.         if (!$res) {
  966.             echo '<i>' . $strNoPrivileges . '</i>' . "\n";
  967.             @mysql_free_result($res);
  968.             unset($res);
  969.         } else {
  970.             if ($oldPrivTables) {
  971.                 // rabus: This message is hardcoded because I will replace it by
  972.                 // a automatic repair feature soon.
  973.                 echo '<div class="warning">' . "\n"
  974.                    . '    Warning: Your privilege table structure seem to be older than this MySQL version!<br />' . "\n"
  975.                    . '    Please run the script <tt>mysql_fix_privilege_tables</tt> that should be included in your MySQL server distribution to solve this problem!' . "\n"
  976.                    . '</div><br />' . "\n";
  977.             }
  978.             echo '<form name="usersForm" action="server_privileges.php" method="post" />' . "\n"
  979.                . PMA_generate_common_hidden_inputs('', '', 1)
  980.                . '    <table border="0">' . "\n"
  981.                . '        <tr>' . "\n"
  982.                . '            <th></th>' . "\n"
  983.                . '            <th> ' . $strUser . ' </th>' . "\n"
  984.                . '            <th> ' . $strHost . ' </th>' . "\n"
  985.                . '            <th> ' . $strPassword . ' </th>' . "\n"
  986.                . '            <th> ' . $strGlobalPrivileges . ' </th>' . "\n"
  987.                . '            <th> ' . $strGrantOption . ' </th>' . "\n"
  988.                . '            <th> ' . $strAction . ' </th>' . "\n";
  989.             echo '        </tr>' . "\n";
  990.             $useBgcolorOne = TRUE;
  991.             for ($i = 0; $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC); $i++) {
  992.                 echo '        <tr>' . "\n"
  993.                    . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><input type="checkbox" name="selected_usr[]" id="checkbox_sel_users_' . $i . '" value="' . htmlspecialchars($row['User'] . '@' . $row['Host']) . '"' . (empty($checkall) ?  '' : ' checked="checked"') . ' /></td>' . "\n"
  994.                    . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><label for="checkbox_sel_users_' . $i . '">' . (empty($row['User']) ? '<span style="color: #FF0000">' . $strAny . '</span>' : htmlspecialchars($row['User'])) . '</label></td>' . "\n"
  995.                    . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . htmlspecialchars($row['Host']) . '</td>' . "\n";
  996.                 $privs = PMA_extractPrivInfo($row, TRUE);
  997.                 echo '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . ($row['Password'] == 'Y' ? $strYes : '<span style="color: #FF0000">' . $strNo . '</span>') . '</td>' . "\n"
  998.                    . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><tt>' . "\n"
  999.                    . '                ' . join(',' . "\n" . '            ', $privs) . "\n"
  1000.                    . '            </tt></td>' . "\n"
  1001.                    . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . ($row['Grant_priv'] == 'Y' ? $strYes : $strNo) . '</td>' . "\n"
  1002.                    . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($row['User']) . '&hostname=' . urlencode($row['Host']) . '">' . $strEdit . '</a></td>' . "\n"
  1003.                    . '        </tr>' . "\n";
  1004.                 $useBgcolorOne = !$useBgcolorOne;
  1005.             }
  1006.             @mysql_free_result($res);
  1007.             unset($res);
  1008.             unset ($row);
  1009.             echo '        <tr>' . "\n"
  1010.                . '            <td></td>' . "\n"
  1011.                . '            <td colspan="5">' . "\n"
  1012.                . '                 <i>' . $strEnglishPrivileges . '</i> ' . "\n"
  1013.                . '            </td>' . "\n"
  1014.                . '        </tr>' . "\n"
  1015.                . '        <tr>' . "\n"
  1016.                . '            <td colspan="6" valign="bottom">' . "\n"
  1017.                . '                <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
  1018.                . '                <a href="./server_privileges.php?' . $url_query .  '&checkall=1" onclick="setCheckboxes(\'usersForm\', \'selected_usr\', true); return false;">' . $strCheckAll . '</a>' . "\n"
  1019.                . '                 / ' . "\n"
  1020.                . '                <a href="server_privileges.php?' . $url_query .  '" onclick="setCheckboxes(\'usersForm\', \'selected_usr\', false); return false;">' . $strUncheckAll . '</a>' . "\n"
  1021.                . '            </td>' . "\n"
  1022.                . '        </tr>' . "\n"
  1023.                . '    </table>' . "\n"
  1024.                . '    <ul>' . "\n"
  1025.                . '        <li>' . "\n"
  1026.                . '            <b><a href="server_privileges.php?' . $url_query . '&adduser=1">' . $strAddUser . '</a></b><br />' . "\n"
  1027.                . '        </li><br /><br />' . "\n"
  1028.                . '        <li>' . "\n"
  1029.                . '            <b>' . $strRemoveSelectedUsers . '</b><br />' . "\n"
  1030.                . '            <input type="radio" title="' . $strJustDelete . ' ' . $strJustDeleteDescr . '" name="mode" id="radio_mode_1" value="1" checked="checked" />' . "\n"
  1031.                . '            <label for="radio_mode_1" title="' . $strJustDelete . ' ' . $strJustDeleteDescr . '">' . "\n"
  1032.                . '                ' . $strJustDelete . "\n"
  1033.                . '            </label><br />' . "\n";
  1034.             if (PMA_MYSQL_INT_VERSION >= 32304) {
  1035.                 echo '            <input type="radio" title="' . $strRevokeAndDelete . ' ' . $strRevokeAndDeleteDescr . '" name="mode" id="radio_mode_2" value="2" />' . "\n"
  1036.                    . '            <label for="radio_mode_2" title="' . $strRevokeAndDelete . ' ' . $strRevokeAndDeleteDescr . '">' . "\n"
  1037.                    . '                ' . $strRevokeAndDelete . "\n"
  1038.                    . '            </label><br />' . "\n";
  1039.             }
  1040.             echo '            <input type="radio" title="' . $strDeleteAndFlush . ' ' . $strDeleteAndFlushDescr . '" name="mode" id="radio_mode_3" value="3" />' . "\n"
  1041.                . '            <label for="radio_mode_3" title="' . $strDeleteAndFlush . ' ' . $strDeleteAndFlushDescr . '">' . "\n"
  1042.                . '                ' . $strDeleteAndFlush . "\n"
  1043.                . '            </label><br />' . "\n"
  1044.                . '            <input type="checkbox" title="' . $strDropUsersDb . '" name="drop_users_db" id="checkbox_drop_users_db" />' . "\n"
  1045.                . '            <label for="checkbox_drop_users_db" title="' . $strDropUsersDb . '">' . "\n"
  1046.                . '                ' . $strDropUsersDb . "\n"
  1047.                . '            </label><br />' . "\n"
  1048.                . '            <input type="submit" name="delete" value="' . $strGo . '" />' . "\n"
  1049.                . '        </li>' . "\n"
  1050.                . '    </ul>' . "\n"
  1051.                . '</form>' . "\n"
  1052.                . '<div>' . "\n"
  1053.                . '    ' . sprintf($strFlushPrivilegesNote, '<a href="server_privileges.php?' . $url_query . '&flush_privileges=1">', '</a>') . "\n"
  1054.                . '</div>' . "\n";
  1055.         }
  1056.     } else {
  1057.         // A user was selected -> display the user's properties
  1058.         echo '<h2>' . "\n"
  1059.            . '    ' . $strUser . ' <i><a class="h2" href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '">\'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'</a></i>' . "\n";
  1060.         if (!empty($dbname)) {
  1061.             echo '    - ' . $strDatabase . ' <i><a class="h2" href="' . $cfg['DefaultTabDatabase'] . '?' . $url_query . '&db=' . urlencode($dbname) . '&reload=1">' . htmlspecialchars($dbname) . '</a></i>' . "\n";
  1062.             if (!empty($tablename)) {
  1063.                 echo '    - ' . $strTable . ' <i><a class="h2" href="' . $cfg['DefaultTabTable'] . '?' . $url_query . '&db=' . urlencode($dbname) . '&table=' . urlencode($tablename) . '&reload=1">' . htmlspecialchars($tablename) . '</a></i>' . "\n";
  1064.             }
  1065.         }
  1066.         echo '</h2>' . "\n";
  1067.         $res = PMA_mysql_query('SELECT "foo" FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '";', $userlink);
  1068.         if (mysql_affected_rows($userlink) <= 0) {
  1069.             echo $strUserNotFound;
  1070.             include('./footer.inc.php');
  1071.             exit;
  1072.         }
  1073.         mysql_free_result($res);
  1074.         unset($res);
  1075.         echo '<ul>' . "\n"
  1076.            . '    <li>' . "\n"
  1077.            . '        <form action="server_privileges.php" method="post">' . "\n"
  1078.            . PMA_generate_common_hidden_inputs('', '', 3)
  1079.            . '            <input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
  1080.            . '            <input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n";
  1081.         if (!empty($dbname)) {
  1082.             echo '            <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '" />' . "\n";
  1083.             if (!empty($tablename)) {
  1084.                 echo '            <input type="hidden" name="tablename" value="' . htmlspecialchars($tablename) . '" />' . "\n";
  1085.             }
  1086.         }
  1087.         echo '            <b>' . $strEditPrivileges . '</b><br />' . "\n";
  1088.         PMA_displayPrivTable((empty($dbname) ? '*' : $dbname), ((empty($dbname) || empty($tablename)) ? '*' : $tablename), TRUE, 3);
  1089.         echo '        </form>' . "\n"
  1090.            . '    </li>' . "\n";
  1091.         if (empty($tablename)) {
  1092.             echo '    <li>' . "\n"
  1093.                . '        <b>' . (empty($dbname) ? $strDbPrivileges : $strTblPrivileges) . '</b><br />' . "\n"
  1094.                . '        <table border="0">' . "\n"
  1095.                . '            <tr>' . "\n"
  1096.                . '                <th> ' . (empty($dbname) ? $strDatabase : $strTable) . ' </th>' . "\n"
  1097.                . '                <th> ' . $strPrivileges . ' </th>' . "\n";
  1098.             if (PMA_MYSQL_INT_VERSION >= 32211) {
  1099.                 echo '                <th> ' . $strGrantOption . ' </th>' . "\n";
  1100.             }
  1101.             echo '                <th> ' . (empty($dbname) ? $strTblPrivileges : $strColumnPrivileges) . ' </th>' . "\n"
  1102.                . '                <th colspan="2"> ' . $strAction . ' </th>' . "\n"
  1103.                . '            </tr>' . "\n";
  1104.             if (empty($dbname)) {
  1105.                 $sql_query = 'SELECT * FROM `db` WHERE `Host` = "' . $hostname . '" AND `User` = "' . PMA_sqlAddslashes($username) . '" ORDER BY `Db` ASC;';
  1106.             } else {
  1107.                 $sql_query = 'SELECT `Table_name`, `Table_priv`, IF(`Column_priv` = "", 0, 1) AS "Column_priv" FROM `tables_priv` WHERE `Host` = "' . $hostname . '" AND `User` = "' . PMA_sqlAddslashes($username) . '" AND `Db` = "' . $dbname . '" ORDER BY `Table_name` ASC;';
  1108.             }
  1109.             $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  1110.             if (mysql_affected_rows($userlink) == 0) {
  1111.                 echo '            <tr>' . "\n"
  1112.                    . '                <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="' .(PMA_MYSQL_INT_VERSION >= 32211 ? '6' : '5') . '"><center><i>' . $strNone . '</i></center></td>' . "\n"
  1113.                    . '            </tr>' . "\n";
  1114.             } else {
  1115.                 $useBgcolorOne = TRUE;
  1116.                 if (empty($dbname)) {
  1117.                     $res2 = PMA_mysql_query('SELECT `Db` FROM `tables_priv` WHERE `Host` = "' . $hostname . '" AND `User` = "' . PMA_sqlAddslashes($username) . '" GROUP BY `Db` ORDER BY `Db` ASC;') or PMA_mysqlDie(PMA_mysql_error($userlink), 'SELECT `Db` FROM `tables_priv` WHERE `Host` = "' . $hostname . '" AND `User` = "' . PMA_sqlAddslashes($username) . '" GROUP BY `Db` ORDER BY `Db` ASC;');
  1118.                     $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
  1119.                 }
  1120.                 $found_rows = array();
  1121.                 while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
  1122.                     while (empty($dbname) && $row2 && $row['Db'] > $row2['Db']) {
  1123.                         $found_rows[] = $row2['Db'];
  1124.                         echo '            <tr>' . "\n"
  1125.                            . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . htmlspecialchars($row2['Db']) . '</td>' . "\n"
  1126.                            . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><tt>' . "\n"
  1127.                            . '                    <dfn title="' . $strPrivDescUsage . '">USAGE</dfn>' . "\n"
  1128.                            . '                </tt></td>' . "\n";
  1129.                         if (PMA_MYSQL_INT_VERSION >= 32211) {
  1130.                             echo '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . $strNo . '</td>' . "\n";
  1131.                         }
  1132.                         echo '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . $strYes . '</td>' . "\n"
  1133.                            . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . urlencode($row2['Db']) . '">' . $strEdit . '</a></td>' . "\n"
  1134.                            . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . urlencode($row2['Db']) . '&revokeall=1">' . $strRevoke . '</a></td>' . "\n"
  1135.                            . '            </tr>' . "\n";
  1136.                         $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
  1137.                         $useBgcolorOne = !$useBgcolorOne;
  1138.                     } // end while
  1139.                     $found_rows[] = empty($dbname) ? $row['Db'] : $row['Table_name'];
  1140.                     echo '            <tr>' . "\n"
  1141.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . htmlspecialchars(empty($dbname) ? $row['Db'] : $row['Table_name']) . '</td>' . "\n"
  1142.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><tt>' . "\n"
  1143.                        . '                    ' . join(',' . "\n" . '            ', PMA_extractPrivInfo($row, TRUE)) . "\n"
  1144.                        . '                </tt></td>' . "\n";
  1145.                     if (PMA_MYSQL_INT_VERSION >= 32211) {
  1146.                         echo '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . (((empty($dbname) && $row['Grant_priv'] == 'Y') || (!empty($dbname) && in_array('Grant', explode(',', $row['Table_priv'])))) ? $strYes : $strNo) . '</td>' . "\n";
  1147.                     }
  1148.                     echo '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">';
  1149.                     if ((empty($dbname) && $row2 && $row['Db'] == $row2['Db'])
  1150.                         || (!empty($dbname) && $row['Column_priv'])) {
  1151.                         echo $strYes;
  1152.                         if (empty($dbname)) {
  1153.                             $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
  1154.                         }
  1155.                     } else {
  1156.                         echo $strNo;
  1157.                     }
  1158.                     echo '</td>' . "\n"
  1159.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . (empty($dbname) ? urlencode($row['Db']) : urlencode($dbname) . '&tablename=' . urlencode($row['Table_name'])) . '">' . $strEdit . '</a></td>' . "\n"
  1160.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . (empty($dbname) ? urlencode($row['Db']) : urlencode($dbname) . '&tablename=' . urlencode($row['Table_name'])) . '&revokeall=1">' . $strRevoke . '</a></td>' . "\n"
  1161.                        . '            </tr>' . "\n";
  1162.                     $useBgcolorOne = !$useBgcolorOne;
  1163.                 } // end while
  1164.                 while (empty($dbname) && $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC)) {
  1165.                     $found_rows[] = $row2['Db'];
  1166.                     echo '            <tr>' . "\n"
  1167.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . htmlspecialchars($row2['Db']) . '</td>' . "\n"
  1168.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><tt>' . "\n"
  1169.                        . '                    <dfn title="' . $strPrivDescUsage . '">USAGE</dfn>' . "\n"
  1170.                        . '                </tt></td>' . "\n";
  1171.                     if (PMA_MYSQL_INT_VERSION >= 32211) {
  1172.                         echo '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . $strNo . '</td>' . "\n";
  1173.                     }
  1174.                     echo '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . $strYes . '</td>' . "\n"
  1175.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . urlencode($row2['Db']) . '">' . $strEdit . '</a></td>' . "\n"
  1176.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . urlencode($row2['Db']) . '&revokeall=1">' . $strRevoke . '</a></td>' . "\n"
  1177.                        . '            </tr>' . "\n";
  1178.                     $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
  1179.                     $useBgcolorOne = !$useBgcolorOne;
  1180.                 } // end while
  1181.                 if (empty($dbname)) {
  1182.                     mysql_free_result($res2);
  1183.                     unset($res2);
  1184.                     unset($row2);
  1185.                 }
  1186.             }
  1187.             mysql_free_result($res);
  1188.             unset($res);
  1189.             unset($row);
  1190.             echo '            <tr>' . "\n"
  1191.                . '                <td colspan="' .(PMA_MYSQL_INT_VERSION >= 32211 ? '5' : '4') . '">' . "\n"
  1192.                . '                    <form action="server_privileges.php" method="post">' . "\n"
  1193.                . PMA_generate_common_hidden_inputs('', '', 6)
  1194.                . '                        <input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
  1195.                . '                        <input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n";
  1196.             if (empty($dbname)) {
  1197.                 echo '                        <label for="text_dbname">' . $strAddPrivilegesOnDb . ':</label>' . "\n";
  1198.                 $res = PMA_mysql_query('SHOW DATABASES;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW DATABASES;');
  1199.                 $pred_db_array = array();
  1200.                 while ($row = PMA_mysql_fetch_row($res)) {
  1201.                     if (!isset($found_rows) || !in_array($row[0], $found_rows)) {
  1202.                         $pred_db_array[] = $row[0];
  1203.                     }
  1204.                 }
  1205.                 mysql_free_result($res);
  1206.                 unset($res);
  1207.                 unset($row);
  1208.                 if (!empty($pred_db_array)) {
  1209.                     echo '                        <select name="pred_dbname" onchange="this.form.submit();">' . "\n"
  1210.                        . '                            <option value="" selected="selected">' . $strUseTextField . ':</option>' . "\n";
  1211.                     while (list(, $current_db) = each($pred_db_array)) {
  1212.                         echo '                            <option value="' . htmlspecialchars($current_db) . '">' . htmlspecialchars($current_db) . '</option>' . "\n";
  1213.                     }
  1214.                     echo '                        </select>' . "\n";
  1215.                 }
  1216.                 echo '                        <input type="text" id="text_dbname" name="dbname" class="textfield" />' . "\n";
  1217.             } else {
  1218.                 echo '                        <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '"/>' . "\n"
  1219.                    . '                        <label for="text_tablename">' . $strAddPrivilegesOnTbl . ':</label>' . "\n";
  1220.                 if ($res = @PMA_mysql_query('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';', $userlink)) {
  1221.                     $pred_tbl_array = array();
  1222.                     while ($row = PMA_mysql_fetch_row($res)) {
  1223.                         if (!isset($found_rows) || !in_array($row[0], $found_rows)) {
  1224.                             $pred_tbl_array[] = $row[0];
  1225.                         }
  1226.                     }
  1227.                     mysql_free_result($res);
  1228.                     unset($res);
  1229.                     unset($row);
  1230.                     if (!empty($pred_tbl_array)) {
  1231.                         echo '                        <select name="pred_tablename" onchange="this.form.submit();">' . "\n"
  1232.                            . '                            <option value="" selected="selected">' . $strUseTextField . ':</option>' . "\n";
  1233.                         while (list(, $current_table) = each($pred_tbl_array)) {
  1234.                             echo '                            <option value="' . htmlspecialchars($current_table) . '">' . htmlspecialchars($current_table) . '</option>' . "\n";
  1235.                         }
  1236.                         echo '                        </select>' . "\n";
  1237.                     }
  1238.                 } else {
  1239.                     unset($res);
  1240.                 }
  1241.                 echo '                        <input type="text" id="text_tablename" name="tablename" class="textfield" />' . "\n";
  1242.             }
  1243.             echo '                        <input type="submit" value="' . $strGo . '" />' . "\n"
  1244.                . '                    </form>' . "\n"
  1245.                . '                </td>' . "\n"
  1246.                . '            </tr>' . "\n"
  1247.                . '        </table><br />' . "\n"
  1248.                . '    </li>' . "\n";
  1249.         }
  1250.         if (empty($dbname)) {
  1251.             echo '    <li>' . "\n"
  1252.                . '        <form action="server_privileges.php" method="post" onsubmit="checkPassword(this);">' . "\n"
  1253.                . PMA_generate_common_hidden_inputs('', '', 3)
  1254.                . '            <input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
  1255.                . '            <input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n";
  1256.             echo '            <b>' . $strChangePassword . '</b><br />' . "\n"
  1257.                . '            <table border="0">' . "\n"
  1258.                . '                <tr>' . "\n"
  1259.                . '                    <td bgcolor="' . $cfg['BgcolorOne'] . '"><input type="radio" name="nopass" value="1" id="radio_nopass_1" onclick="pma_pw.value=\'\'; pma_pw2.value=\'\';" /></td>' . "\n"
  1260.                . '                    <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2"><label for="radio_nopass_1">' . $strNoPassword . '</label></td>' . "\n"
  1261.                . '                </tr>' . "\n"
  1262.                . '                <tr>' . "\n"
  1263.                . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="radio" name="nopass" value="0" id="radio_nopass_0" onclick="document.getElementById(\'pw_pma_pw\').focus();" /></td>' . "\n"
  1264.                . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="radio_nopass_0">' . $strPassword . ':</label></td>' . "\n"
  1265.                . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="password" name="pma_pw" id="pw_pma_pw" class="textfield" onchange="nopass[1].checked = true;" /></td>' . "\n"
  1266.                . '                </tr>' . "\n"
  1267.                . '                <tr>' . "\n"
  1268.                . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"> </td>' . "\n"
  1269.                . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="pw_pma_pw2">' . $strReType . ':</label></td>' . "\n"
  1270.                . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="password" name="pma_pw2" id="pw_pma_pw2" class="textfield" onchange="nopass[1].checked = true;" /></td>' . "\n"
  1271.                . '                </tr>' . "\n"
  1272.                . '                <tr>' . "\n"
  1273.                . '                    <td colspan="3" align="center">' . "\n"
  1274.                . '                        <input type="submit" name="change_pw" value="' . $strGo . '" />' . "\n"
  1275.                . '                    </td>' . "\n"
  1276.                . '                </tr>' . "\n"
  1277.                . '            </table>' . "\n"
  1278.                . '        </form>' . "\n"
  1279.                . '    </li>' . "\n";
  1280.             if (PMA_MYSQL_INT_VERSION >= 32211) {
  1281.                 echo '    <li>' . "\n"
  1282.                    . '        <form action="server_privileges.php" method="post" onsubmit="checkPassword(this);">' . "\n"
  1283.                    . PMA_generate_common_hidden_inputs('', '', 3)
  1284.                    . '            <input type="hidden" name="old_username" value="' . htmlspecialchars($username) . '" />' . "\n"
  1285.                    . '            <input type="hidden" name="old_hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n";
  1286.                 echo '            <b>' . $strChangeCopyUser . '</b><br />' . "\n"
  1287.                    . '            <table border="0">' . "\n";
  1288.                 PMA_displayLoginInformationFields('change', 3);
  1289.                 echo '            </table>' . "\n"
  1290.                    . '            ' . $strChangeCopyMode . '<br />' . "\n"
  1291.                    . '            <input type="radio" name="mode" value="4" id="radio_mode_4" checked="checked" />' . "\n"
  1292.                    . '            <label for="radio_mode_4">' . "\n"
  1293.                    . '                ' . $strChangeCopyModeCopy . "\n"
  1294.                    . '            </label>' . "\n"
  1295.                    . '            <br />' . "\n"
  1296.                    . '            <input type="radio" name="mode" value="1" id="radio_mode_1" />' . "\n"
  1297.                    . '            <label for="radio_mode_1">' . "\n"
  1298.                    . '                ' . $strChangeCopyModeJustDelete . "\n"
  1299.                    . '            </label>' . "\n"
  1300.                    . '            <br />' . "\n"
  1301.                    . '            <input type="radio" name="mode" value="2" id="radio_mode_2" />' . "\n"
  1302.                    . '            <label for="radio_mode_2">' . "\n"
  1303.                    . '                ' . $strChangeCopyModeRevoke . "\n"
  1304.                    . '            </label>' . "\n"
  1305.                    . '            <br />' . "\n"
  1306.                    . '            <input type="radio" name="mode" value="3" id="radio_mode_3" />' . "\n"
  1307.                    . '            <label for="radio_mode_3">' . "\n"
  1308.                    . '                ' . $strChangeCopyModeDeleteAndReload . "\n"
  1309.                    . '            </label>' . "\n"
  1310.                    . '            <br />' . "\n"
  1311.                    . '            <input type="submit" name="change_copy" value="' . $strGo . '" />' . "\n"
  1312.                    . '        </form>' . "\n"
  1313.                    . '    </li>' . "\n";
  1314.             }
  1315.         }
  1316.         echo '</ul>' . "\n";
  1317.     }
  1318. } else if (!empty($adduser)) {
  1319.     // Add a new user
  1320.     echo '<h2>' . "\n"
  1321.        . '    ' . $strAddUser . "\n"
  1322.        . '</h2>' . "\n"
  1323.        . '<form action="server_privileges.php" method="post" onsubmit="return checkAddUser(this);">' . "\n"
  1324.        . PMA_generate_common_hidden_inputs('', '', 1)
  1325.        . '    <table border="0">' . "\n"
  1326.        . '        <tr>' . "\n"
  1327.        . '            <th colspan="3">' . "\n"
  1328.        . '                ' . $strLoginInformation . "\n"
  1329.        . '            </th>' . "\n"
  1330.        . '        </tr>' . "\n";
  1331.     PMA_displayLoginInformationFields('new', 2);
  1332.     echo '    </table><br />' . "\n";
  1333.     PMA_displayPrivTable('*', '*', FALSE, 1);
  1334.     echo '    <br />' . "\n"
  1335.        . '    <input type="submit" name="adduser_submit" value="' . $strGo . '" />' . "\n"
  1336.        . '</form>' . "\n";
  1337. } else {
  1338.     // check the privileges for a particular database.
  1339.     echo '<h2>' . "\n"
  1340.        . '    ' . sprintf($strUsersHavingAccessToDb, htmlspecialchars($checkprivs)) . "\n"
  1341.        . '</h2>' . "\n"
  1342.        . '<table border="0">' . "\n"
  1343.        . '    <tr>' . "\n"
  1344.        . '        <th>' . "\n"
  1345.        . '             ' . $strUser . ' ' . "\n"
  1346.        . '        </th>' . "\n"
  1347.        . '        <th>' . "\n"
  1348.        . '             ' . $strHost . ' ' . "\n"
  1349.        . '        </th>' . "\n"
  1350.        . '        <th>' . "\n"
  1351.        . '             ' . $strType . ' ' . "\n"
  1352.        . '        </th>' . "\n"
  1353.        . '        <th>' . "\n"
  1354.        . '             ' . $strPrivileges . ' ' . "\n"
  1355.        . '        </th>' . "\n";
  1356.     if (PMA_MYSQL_INT_VERSION >= 32211) {
  1357.         echo '        <th>' . "\n"
  1358.            . '             ' . $strGrantOption . ' ' . "\n"
  1359.            . '        </th>' . "\n";
  1360.     }
  1361.     echo '        <th>' . "\n"
  1362.        . '             ' . $strAction . ' ' . "\n"
  1363.        . '        </th>' . "\n"
  1364.        . '    </tr>' . "\n";
  1365.     $useBgcolorOne = TRUE;
  1366.     unset($row);
  1367.     unset($row1);
  1368.     unset($row2);
  1369.     // now, we build the table...
  1370.     if (PMA_MYSQL_INT_VERSION >= 40000) {
  1371.         // Starting with MySQL 4.0.0, we may use UNION SELECTs and this makes
  1372.         // the job much easier here!
  1373.         $sql_query = '(SELECT `User`, `Host`, `Db`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv` FROM `db` WHERE "' . $checkprivs . '" LIKE `Db` AND NOT (`Select_priv` = "N" AND `Insert_priv` = "N" AND `Update_priv` = "N" AND `Delete_priv` = "N" AND `Create_priv` = "N" AND `Drop_priv` = "N" AND `Grant_priv` = "N" AND `References_priv` = "N")) UNION (SELECT `User`, `Host`, "*" AS "Db", `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv` FROM `user` WHERE NOT (`Select_priv` = "N" AND `Insert_priv` = "N" AND `Update_priv` = "N" AND `Delete_priv` = "N" AND `Create_priv` = "N" AND `Drop_priv` = "N" AND `Grant_priv` = "N" AND `References_priv` = "N")) ORDER BY `User` ASC, `Host` ASC, `Db` ASC;';
  1374.         $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  1375.         $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
  1376.         if ($row) {
  1377.             $found = TRUE;
  1378.         }
  1379.     } else {
  1380.         // With MySQL 3, we need 2 seperate queries here.
  1381.         $sql_query = 'SELECT * FROM `user` WHERE NOT (`Select_priv` = "N" AND `Insert_priv` = "N" AND `Update_priv` = "N" AND `Delete_priv` = "N" AND `Create_priv` = "N" AND `Drop_priv` = "N" ' . (PMA_MYSQL_INT_VERSION >= 32211 ? 'AND `Grant_priv` = "N" ' : '') . 'AND `References_priv` = "N") ORDER BY `User` ASC, `Host` ASC;';
  1382.         $res1 = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  1383.         $row1 = PMA_mysql_fetch_array($res1, MYSQL_ASSOC);
  1384.         $sql_query = 'SELECT * FROM `db` WHERE "' . $checkprivs . '" LIKE `Db` AND NOT (`Select_priv` = "N" AND `Insert_priv` = "N" AND `Update_priv` = "N" AND `Delete_priv` = "N" AND `Create_priv` = "N" AND `Drop_priv` = "N" ' . (PMA_MYSQL_INT_VERSION >= 32211 ? 'AND `Grant_priv` = "N" ' : '') . 'AND `References_priv` = "N") ORDER BY `User` ASC, `Host` ASC;';
  1385.         $res2 = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  1386.         $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
  1387.         if ($row1 || $row2) {
  1388.             $found = TRUE;
  1389.         }
  1390.     } // end if (PMA_MYSQL_INT_VERSION >= 40000) ... else ...
  1391.     if ($found) {
  1392.         while (TRUE) {
  1393.             // prepare the current user
  1394.             if (PMA_MYSQL_INT_VERSION >= 40000) {
  1395.                 $current_privileges = array();
  1396.                 $current_user = $row['User'];
  1397.                 $current_host = $row['Host'];
  1398.                 while ($row && $current_user == $row['User'] && $current_host == $row['Host']) {
  1399.                     $current_privileges[] = $row;
  1400.                     $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
  1401.                 }
  1402.             } else {
  1403.                 $current_privileges = array();
  1404.                 if ($row1 && (!$row2 || ($row1['User'] < $row2['User'] || ($row1['User'] == $row2['User'] && $row1['Host'] <= $row2['Host'])))) {
  1405.                     $current_user = $row1['User'];
  1406.                     $current_host = $row1['Host'];
  1407.                     $current_privileges = array($row1);
  1408.                     $row1 = PMA_mysql_fetch_array($res1, MYSQL_ASSOC);
  1409.                 } else {
  1410.                     $current_user = $row2['User'];
  1411.                     $current_host = $row2['Host'];
  1412.                     $current_privileges = array();
  1413.                 }
  1414.                 while ($row2 && $current_user == $row2['User'] && $current_host == $row2['Host']) {
  1415.                     $current_privileges[] = $row2;
  1416.                     $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
  1417.                 }
  1418.             }
  1419.             echo '    <tr>' . "\n"
  1420.                . '        <td';
  1421.             if (count($current_privileges) > 1) {
  1422.                 echo ' rowspan="' . count($current_privileges) . '"';
  1423.             }
  1424.             echo ' bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  1425.                . '            ' . (empty($current_user) ? '<span style="color: #FF0000">' . $strAny . '</span>' : htmlspecialchars($current_user)) . "\n"
  1426.                . '        </td>' . "\n"
  1427.                . '        <td';
  1428.             if (count($current_privileges) > 1) {
  1429.                 echo ' rowspan="' . count($current_privileges) . '"';
  1430.             }
  1431.             echo ' bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  1432.                . '            ' . htmlspecialchars($current_host) . "\n"
  1433.                . '        </td>' . "\n";
  1434.             while (list(, $current) = each($current_privileges)) {
  1435.                 echo '        <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  1436.                    . '            ';
  1437.                 if (!isset($current['Db']) || $current['Db'] == '*') {
  1438.                     echo $strGlobal;
  1439.                 } else if ($current['Db'] == $checkprivs) {
  1440.                     echo $strDbSpecific;
  1441.                 } else {
  1442.                     echo $strWildcard, ': <tt>' . htmlspecialchars($current['Db']) . '</tt>';
  1443.                 }
  1444.                 echo "\n"
  1445.                    . '        </td>' . "\n"
  1446.                    . '        <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  1447.                    . '            <tt>' . "\n"
  1448.                    . '                ' . join(',' . "\n" . '                ', PMA_extractPrivInfo($current, TRUE)) . "\n"
  1449.                    . '            <tt>' . "\n"
  1450.                    . '        </td>' . "\n";
  1451.                 if (PMA_MYSQL_INT_VERSION >= 32211) {
  1452.                     echo '        <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  1453.                        . '            ' . ($current['Grant_priv'] == 'Y' ? $strYes : $strNo) . "\n"
  1454.                        . '        </td>' . "\n";
  1455.                 }
  1456.                 echo '        <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  1457.                    . '            <a href="./server_privileges.php?' . $url_query . '&username=' . urlencode($current_user) . '&hostname=' . urlencode($current_host) . (!isset($current['Db']) || $current['Db'] == '*' ? '' : '&dbname=' . urlencode($current['Db'])) . '">' . "\n"
  1458.                    . '                ' . $strEdit . "\n"
  1459.                    . '            </a>' . "\n"
  1460.                    . '        </td>' . "\n"
  1461.                    . '    </tr>' . "\n";
  1462.             }
  1463.             if (empty($row) && empty($row1) && empty($row2)) {
  1464.                 break;
  1465.             }
  1466.             $useBgcolorOne = !$useBgcolorOne;
  1467.         }
  1468.     } else {
  1469.         echo '    <tr>' . "\n"
  1470.            . '        <td colspan="' . (PMA_MYSQL_INT_VERSION >= 32211 ? '5' : '6') . '" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  1471.            . '            ' . $strNoUsersFound . "\n"
  1472.            . '        </td>' . "\n"
  1473.            . '    </tr>' . "\n";
  1474.     }
  1475.     echo '</table>' . "\n";
  1476. } // end if (empty($adduser) && empty($checkprivs)) ... else if ... else ...
  1477.  
  1478.  
  1479. /**
  1480.  * Displays the footer
  1481.  */
  1482. echo "\n\n";
  1483. require('./footer.inc.php');
  1484.  
  1485. ?>
  1486.